<?php

namespace app\admin\controller;

use think\facade\Db;

class Shop extends Backend
{

    public function getIndexDataList()
    {
        $param = request()->param();


        if (!isset($param['add_time'])) {


            $add_time = date('Y-m-d', strtotime(date('Y-m-d', time())) - 6 * 86400);

            $end_time = date('Y-m-d', strtotime(date('Y-m-d', time())));
        } else {
            $add_time = date('Y-m-d', strtotime($param['add_time']));
            $end_time = date('Y-m-d', strtotime($param['end_time']));
        }

        $where = [];
        if (isset($param['store_id'])) {
            $where[] = ['store_id', '=', $param['store_id']];
        }
        $ti = intval((strtotime($end_time) + 86400 - strtotime($add_time)) / 86400);
        $data = array();
        $data['order'] = array();

        $price = 0;
        $wheres [] = ['pay_time', '>=', strtotime($add_time)];
        $wheres [] = ['pay_time', '<=', strtotime($end_time)];


        for ($i = 0; $i < $ti; $i++) {

            $wheres = [];
            $add = strtotime($add_time) + $i * 86400;
            $end = strtotime($add_time) + 86400 + $i * 86400;
            $wheres [] = ['pay_time', '>=', $add];
            $wheres [] = ['pay_time', '<=', $end];
            $wheredd [] = ['create_time', '>=', $add];
            $wheredd [] = ['create_time', '<=', $end];
            $sotreseatPirce = Db::name('customer_order')->where('pay_type', 1)->where('pay_price', '>', 0)->where('status', '>', 0)->where('status', '<>', 3)->where($where)->where($wheres)->sum('pay_price');
            $sotreseatPircej = Db::name('customer_order')->where('pay_price', '>', 0)->where('status', '>', 0)->where('status', '<>', 3)->where($where)->where($wheres)->sum('jia_price');
            //加时单微信
            $renewalPirce = Db::name('customer_renewal_order')->where('pay_type', 1)->where('pay_price', '>', 0)->where('status', '>', 0)->where('status', '<>', 3)->where($where)->where($wheres)->sum('pay_price');
            $ordersum = Db::name('customer_order')->where('pay_type', 1)->where('status', '>', 0)->where('status', '<>', 3)->where($where)->where($wheres)->count('*');
            //抖音美团微信
            $dmPirce = Db::name('customer_order')->whereIn('pay_type', ['3','4'])->where('status', '>', 0)->where('pay_price', '>', 0)->where('status', '<>', 3)->where($where)->where($wheres)->sum('pay_price');
            $sotreseatPirce=round($sotreseatPirce+$dmPirce-$sotreseatPircej+$renewalPirce,2);
         
         
            $sotrerechargePirce = Db::name('customer_recharge_order')->where('status', '>', 0)->where($where)->where($wheres)->sum('price');
         
            $couponPirce = Db::name('customer_coupon_order')->where('status', '>', 0)->where('status', '<>', 3)->where($where)->where($wheres)->sum('price');

       
            $data['order'][] = array(
                'create_time' => date('Y-m-d', $add),
                'order_price' => $sotreseatPirce,//正常
                'renewalorder_price'=>$renewalPirce,//加时
                'user_price' => $sotrerechargePirce,
                'coupon_price' => $couponPirce,//团购卷
                'ordersum'=>$ordersum,
            );
        }
        $count = 0;
        foreach ($data['order'] as $i => $v) {
            $shopprice = $v['order_price'] + $v['user_price']+$v['coupon_price'];
            $count += $shopprice;
        }
        $data['shopprice'] = round($count, 2);
        return message('成功', true, $data);

    }
}